import mergeJSON from '@/utils/common/mergeJSON'
const barOption = function (obj = {}) {
  // 默认值
  let _object = {
    color: ['#3398DB'],
    title: {
      text: '默认值',
      left: 'center',
      textStyle: {
        fontSize: 30
      }
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: { // 坐标轴指示器，坐标轴触发有效
        type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    // 工具栏
    toolbox: {
      show: true,
      feature: {
        mark: { show: true },
        dataView: { show: true, readOnly: false },
        // magicType: {
        //   show: true,
        //   type: ['bar', 'funnel']
        // },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: obj.xAxis.map(item => (
      {
        type: item.type || 'category',
        axisLabel: {
          rotate: 45
        }
      }
    )),
    yAxis: obj.yAxis.map(item => (
      {
        type: item.type || 'value',
        axisLabel: {
          rotate: 45
        }
      }
    )),
    series: obj.series.map(item => ({
      type: item.type || 'bar',
      barWidth: item.barWidth || '60%'
    }))
  }
  return mergeJSON(obj, _object)
}

export default barOption
